<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models\Env;

use App\Models\Api\SampleValue;
use App\Models\Projects\Product;
use Carbon\Carbon;
use App\Models\Eloquent;
/**
 * Class QtpCommonHeader
 *
 * @property int $id
 * @property int $product_id
 * @property string $key
 * @property string $value
 * @property string $remark
 * @property string $created_adminer
 * @property string $updated_adminer
 * @property int $enable
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 *
 * @package App\Models
 */
class CommonHeader extends Eloquent
{
	protected $table = 'common_headers';

	protected $casts = [
		'product_id' => 'int',
		'enable' => 'int'
	];

	protected $fillable = [
		'product_id',
		'key',
		'value',
		'remark',
		'created_adminer',
		'updated_adminer',
		'enable'
	];

    public static $fillables = [
        'product_id' => '产品ID',
        'key' => '请求头名称',
        'value' => '请求头值',
        'remark' => '请求头备注',
        'created_adminer' => '创建人',
        'updated_adminer' => '更新人',
        'enable' => '状态'
    ];

    public function label()
    {
        $this->product_name = Product::find($this->product_id)->name ?? '';
        if(strpos("_".$this->value,'${') == true) {
           $this->true_value = SampleValue::getValue($this->value);
        } else {
            $this->true_value = $this->value;
        }
        return $this;
    }
}
